package com.zyz.user.config;

import com.zyz.user.constant.Constant;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    // 声明队列
    @Bean("userQueue")
    public Queue userQueue() {
        return QueueBuilder.durable(Constant.USER_QUEUE).build();
    }

    @Bean("userExchange")
    public FanoutExchange userExchange() {
        return ExchangeBuilder.fanoutExchange(Constant.USER_EXCHANGE).durable(true).build();
    }

    @Bean("userBinding")
    public Binding userBinding(@Qualifier("userExchange") FanoutExchange userExchange,@Qualifier("userQueue") Queue userQueue) {
        return BindingBuilder.bind(userQueue).to(userExchange);
    }
}
